<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>管理员仪表盘</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
            background: linear-gradient(135deg, #0a2540 0%, #134790 50%, #1e5a9e 100%);
            min-height: 100vh;
            color: #333;
            position: relative;
            overflow-x: hidden;
        }

        body::before {
            content: '';
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: 
                radial-gradient(circle at 20% 80%, rgba(19, 71, 144, 0.3) 0%, transparent 50%),
                radial-gradient(circle at 80% 20%, rgba(30, 90, 158, 0.3) 0%, transparent 50%),
                radial-gradient(circle at 40% 40%, rgba(19, 71, 144, 0.2) 0%, transparent 50%);
            pointer-events: none;
            z-index: 1;
        }

        .container {
            max-width: 1400px;
            margin: 0 auto;
            padding: 40px 20px;
            position: relative;
            z-index: 2;
        }

        h1 {
            color: #fff;
            font-size: 2.5rem;
            font-weight: 600;
            margin-bottom: 40px;
            text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
            letter-spacing: -0.5px;
        }

        /* 统计卡片 - 调整为更紧凑的样式 */
        .stats {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
            gap: 16px;
            margin-bottom: 30px;
        }

        .stat-item {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            border-radius: 12px;
            padding: 16px;
            text-align: center;
            box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
            border: 1px solid rgba(255, 255, 255, 0.2);
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }

        .stat-item:hover {
            transform: translateY(-3px);
            box-shadow: 0 8px 25px rgba(0, 0, 0, 0.12);
        }

        .stat-item h3 {
            font-size: 1.8rem;
            color: #134790;
            font-weight: 700;
            margin-bottom: 4px;
            background: linear-gradient(135deg, #134790, #1e5a9e);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
            line-height: 1.2;
        }

        .stat-item p {
            color: #666;
            font-size: 0.85rem;
            font-weight: 500;
            text-transform: uppercase;
            letter-spacing: 0.3px;
            margin: 0;
        }

        /* 筛选器 */
        .filters {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            border-radius: 16px;
            padding: 24px;
            margin-bottom: 30px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
        }

        .filters form {
            display: flex;
            gap: 15px;
            flex-wrap: wrap;
            align-items: center;
        }

        .filters select {
            flex: 1;
            min-width: 180px;
            padding: 12px 16px;
            border: 2px solid #e0e6ed;
            border-radius: 10px;
            font-size: 0.95rem;
            background: #fff;
            color: #333;
            transition: all 0.3s ease;
            cursor: pointer;
        }

        .filters select:hover {
            border-color: #134790;
        }

        .filters select:focus {
            outline: none;
            border-color: #134790;
            box-shadow: 0 0 0 3px rgba(19, 71, 144, 0.1);
        }

        .filters button {
            padding: 12px 32px;
            background: linear-gradient(135deg, #134790, #1e5a9e);
            color: white;
            border: none;
            border-radius: 10px;
            font-size: 0.95rem;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            box-shadow: 0 4px 15px rgba(19, 71, 144, 0.3);
        }

        .filters button:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 20px rgba(19, 71, 144, 0.4);
        }

        /* 表格 */
        .applications-table {
            width: 100%;
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            border-radius: 16px;
            overflow: hidden;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
        }

        .applications-table thead {
            background: linear-gradient(135deg, #134790, #1e5a9e);
        }

        .applications-table thead th {
            padding: 18px 20px;
            text-align: left;
            color: white;
            font-weight: 600;
            font-size: 0.95rem;
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        .applications-table tbody tr {
            border-bottom: 1px solid #e8ecf1;
            transition: background-color 0.2s ease;
        }

        .applications-table tbody tr:hover {
            background-color: #f8fafb;
        }

        .applications-table tbody tr:last-child {
            border-bottom: none;
        }

        .applications-table tbody td {
            padding: 16px 20px;
            color: #333;
            font-size: 0.95rem;
        }

        /* 用户类型标记 */
        .user-type-badge {
            display: inline-block;
            padding: 6px 12px;
            border-radius: 20px;
            font-size: 0.85rem;
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 0.3px;
        }

        .user-type-badge.supervisor {
            background: linear-gradient(135deg, #667eea, #764ba2);
            color: white;
        }

        .user-type-badge.student {
            background: linear-gradient(135deg, #f093fb, #f5576c);
            color: white;
        }

        /* 状态标记 */
        .status-badge {
            display: inline-block;
            padding: 6px 14px;
            border-radius: 20px;
            font-size: 0.85rem;
            font-weight: 600;
        }

        .status-badge.pending {
            background: #fef3c7;
            color: #92400e;
        }

        .status-badge.approved {
            background: #d1fae5;
            color: #065f46;
        }

        .status-badge.rejected {
            background: #fee2e2;
            color: #991b1b;
        }

        /* 等待审批提示 */
        .waiting-approval {
            color: #f59e0b;
            font-size: 0.85rem;
            font-weight: 500;
        }

        /* 操作按钮 */
        .btn {
            padding: 8px 16px;
            border: none;
            border-radius: 8px;
            font-size: 0.9rem;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            margin: 0 4px;
        }

        .btn-approve {
            background: linear-gradient(135deg, #10b981, #059669);
            color: white;
            box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
        }

        .btn-approve:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
        }

        .btn-reject {
            background: linear-gradient(135deg, #ef4444, #dc2626);
            color: white;
            box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
        }

        .btn-reject:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
        }

        .text-muted {
            color: #9ca3af;
            font-size: 0.9rem;
        }

        /* 导航链接 */
        .nav-links {
            margin-top: 40px;
            display: flex;
            gap: 20px;
            justify-content: center;
        }

        .nav-links a {
            padding: 14px 28px;
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            color: #134790;
            text-decoration: none;
            border-radius: 10px;
            font-weight: 600;
            transition: all 0.3s ease;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
            border: 2px solid transparent;
        }

        .nav-links a:hover {
            background: #134790;
            color: white;
            transform: translateY(-2px);
            box-shadow: 0 6px 20px rgba(19, 71, 144, 0.3);
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            h1 {
                font-size: 2rem;
            }

            .stats {
                grid-template-columns: repeat(2, 1fr);
                gap: 12px;
            }

            .stat-item {
                padding: 12px;
            }

            .stat-item h3 {
                font-size: 1.5rem;
            }

            .stat-item p {
                font-size: 0.8rem;
            }

            .filters form {
                flex-direction: column;
            }

            .filters select,
            .filters button {
                width: 100%;
            }

            .applications-table {
                overflow-x: auto;
                display: block;
            }

            .nav-links {
                flex-direction: column;
            }

            .nav-links a {
                width: 100%;
                text-align: center;
            }
        }

        @media (max-width: 480px) {
            .stats {
                grid-template-columns: 1fr;
            }
        }

        /* 动画效果 */
        @keyframes fadeIn {
            from {
                opacity: 0;
                transform: translateY(20px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .container > * {
            animation: fadeIn 0.6s ease-out;
        }

        .stat-item {
            animation: fadeIn 0.6s ease-out;
            animation-fill-mode: both;
        }

        .stat-item:nth-child(1) { animation-delay: 0.1s; }
        .stat-item:nth-child(2) { animation-delay: 0.2s; }
        .stat-item:nth-child(3) { animation-delay: 0.3s; }
        .stat-item:nth-child(4) { animation-delay: 0.4s; }
    </style>
</head>
<body>
    <div class="container">
        <h1>管理员仪表盘</h1>
        
        <div class="stats">
            <div class="stat-item">
                <h3>{{ stats.total_applications or 0 }}</h3>
                <p>总申请数</p>
            </div>
            <div class="stat-item">
                <h3>{{ stats.pending_applications or 0 }}</h3>
                <p>待审批申请</p>
            </div>
            <div class="stat-item">
                <h3>{{ stats.approved_applications or 0 }}</h3>
                <p>已通过申请</p>
            </div>
            <div class="stat-item">
                <h3>{{ stats.rejected_applications or 0 }}</h3>
                <p>已拒绝申请</p>
            </div>
            <div class="stat-item">
                <h3>{{ stats.student_applications or 0 }}</h3>
                <p>学生申请</p>
            </div>
            <div class="stat-item">
                <h3>{{ stats.supervisor_applications or 0 }}</h3>
                <p>导师申请</p>
            </div>
        </div>
        
        <div class="filters">
            <form method="GET" action="{{ url_for('admin_dashboard') }}">
                <select name="status">
                    <option value="">所有状态</option>
                    <option value="PENDING" {% if request.args.get('status') == 'PENDING' %}selected{% endif %}>待审批</option>
                    <option value="APPROVED" {% if request.args.get('status') == 'APPROVED' %}selected{% endif %}>已通过</option>
                    <option value="REJECTED" {% if request.args.get('status') == 'REJECTED' %}selected{% endif %}>已拒绝</option>
                </select>
                
                <select name="user_type">
                    <option value="">所有类型</option>
                    <option value="STUDENT" {% if request.args.get('user_type') == 'STUDENT' %}selected{% endif %}>学生</option>
                    <option value="SUPERVISOR" {% if request.args.get('user_type') == 'SUPERVISOR' %}selected{% endif %}>导师</option>
                </select>
                
                <select name="supervisor_approval">
                    <option value="">导师审批状态</option>
                    <option value="approved" {% if request.args.get('supervisor_approval') == 'approved' %}selected{% endif %}>已审批</option>
                    <option value="pending" {% if request.args.get('supervisor_approval') == 'pending' %}selected{% endif %}>待审批</option>
                </select>
                
                <button type="submit">筛选</button>
            </form>
        </div>
        
        <table class="applications-table">
            <thead>
                <tr>
                    <th>类型</th>
                    <th>姓名</th>
                    <th>用户名</th>
                    <th>学号</th>
                    <th>邮箱</th>
                    <th>导师/院系</th>
                    <th>状态</th>
                    <th>申请时间</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                {% for app in applications %}
                <tr>
                    <td>
                        <span class="user-type-badge {{ app.user_type.name.lower() }}">
                            {{ app.user_type.value }}
                        </span>
                    </td>
                    <td>{{ app.name }}</td>
                    <td>{{ app.username }}</td>

                    <td>
                        {% if app.user_type.name == 'STUDENT' %}
                            {{ app.student_id or 'N/A' }}
                        {% else %}
                            <span class="text-muted">-</span>
                        {% endif %}
                    </td>

                    <td>{{ app.email }}</td>
                    <td>
                        {% if app.user_type.name == 'SUPERVISOR' %}
                            {{ app.department }}
                        {% else %}
                            {{ app.supervisor_name }}
                            {% if not app.supervisor_approved %}
                                <span class="waiting-approval">(待导师审批)</span>
                            {% endif %}
                        {% endif %}
                    </td>
                    <td>
                        <span class="status-badge {{ app.status.name.lower() }}">
                            {{ app.status.value }}
                        </span>
                    </td>
                    <td>{{ app.submitted_at.strftime('%Y-%m-%d %H:%M') }}</td>
                    <td>
                        {% if app.status.name == 'PENDING' %}
                            {% if app.user_type.name == 'SUPERVISOR' or app.supervisor_approved %}
                                <form method="POST" action="{{ url_for('approve_application', app_id=app.id) }}" style="display: inline;">
                                    <button type="submit" class="btn btn-approve">批准</button>
                                </form>
                                <form method="POST" action="{{ url_for('reject_application', app_id=app.id) }}" style="display: inline;">
                                    <button type="submit" class="btn btn-reject">拒绝</button>
                                </form>
                            {% else %}
                                <span class="text-muted">等待导师审批</span>
                            {% endif %}
                        {% else %}
                            <span class="text-muted">{{ app.status.value }}</span>
                        {% endif %}
                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
        
        <div class="nav-links">
            <a href="{{ url_for('admin_users') }}">用户管理</a>
            <a href="{{ url_for('admin_logout') }}">退出登录</a>
        </div>
    </div>
</body>
</html>